package com.csit.action;

import java.util.Date;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.ParentPackage;

import com.csit.entity.User;
import com.csit.entity.Wastage;
import com.csit.service.WastageService;
import com.csit.util.ResponseMsgUtil;
import com.opensymphony.xwork2.ModelDriven;

/**
 * 
 * @Description: 损耗Action
 * @Copyright: 福州骏华信息有限公司 (c)2012
 * @Created Date : 2012-12-8
 * @author longweier
 * @vesion 1.0
 */
@ParentPackage("basePackage")
public class WastageAction extends BaseAction implements ModelDriven<Wastage> {
	
	private static final long serialVersionUID = -5734652295755361369L;
	
	private Wastage wastage = new Wastage();
	
	private String productids;
	
	private String qtys;
	
	private String prices;
	
	private String notes;
	
	private Date beginDate;
	
	private Date endDate;
	
	@Resource
	private WastageService wastageService;
	
	public Wastage getModel() {
		return wastage;
	}

	/**
	 * 
	 * @Description: 
	 * @param
	 * @Create: 2012-12-8 下午08:41:24
	 * @author longweier
	 * @update logs
	 * @return
	 * @throws Exception
	 */
	public void add(){
		ResponseMsgUtil msgUtil = new ResponseMsgUtil(false);
		try {
			wastage.setShop(getShop());
			String userName = (String) getSession(User.LOGINNAME);
			wastage.setOperater(userName);
			msgUtil = wastageService.addWastage(wastage, productids, qtys, prices, notes);
		} catch (Exception e) {
			e.printStackTrace();
			msgUtil.setMsg("后台出错");
		}
		ajaxJson(msgUtil.toJSON());
	}
	
	/**
	 * 
	 * @Description: 
	 * @param
	 * @Create: 2012-12-8 下午08:42:55
	 * @author longweier
	 * @update logs
	 * @return
	 * @throws Exception
	 */
	public void update(){
		ResponseMsgUtil msgUtil = new ResponseMsgUtil(false);
		try {
			msgUtil = wastageService.updateWastage(wastage);
		} catch (Exception e) {
			e.printStackTrace();
			msgUtil.setMsg("后台出错");
		}
		ajaxJson(msgUtil.toJSON());
	}
	
	/**
	 * 
	 * @Description: 
	 * @param
	 * @Create: 2012-12-8 下午08:42:53
	 * @author longweier
	 * @update logs
	 * @return
	 * @throws Exception
	 */
	public void delete(){
		ResponseMsgUtil msgUtil = new ResponseMsgUtil(false);
		try {
			msgUtil = wastageService.deleteWastage(wastage);
		} catch (Exception e) {
			e.printStackTrace();
			msgUtil.setMsg("后台出错");
		}
		ajaxJson(msgUtil.toJSON());
	}
	
	/**
	 * 
	 * @Description: 
	 * @param
	 * @Create: 2012-12-8 下午08:42:50
	 * @author longweier
	 * @update logs
	 * @return
	 * @throws Exception
	 */
	public void select(){
		String jsonString = wastageService.query(page, rows, wastage, beginDate, endDate);
		ajaxJson(jsonString);
	}
	
	/**
	 * 
	 * @Description: 
	 * @param
	 * @Create: 2012-12-8 下午08:42:46
	 * @author longweier
	 * @update logs
	 * @return
	 * @throws Exception
	 */
	public void get(){
		
	}

	public String getProductids() {
		return productids;
	}

	public void setProductids(String productids) {
		this.productids = productids;
	}

	public String getQtys() {
		return qtys;
	}

	public void setQtys(String qtys) {
		this.qtys = qtys;
	}

	public String getPrices() {
		return prices;
	}

	public void setPrices(String prices) {
		this.prices = prices;
	}

	public String getNotes() {
		return notes;
	}

	public void setNotes(String notes) {
		this.notes = notes;
	}

	public Date getBeginDate() {
		return beginDate;
	}

	public void setBeginDate(Date beginDate) {
		this.beginDate = beginDate;
	}

	public Date getEndDate() {
		return endDate;
	}

	public void setEndDate(Date endDate) {
		this.endDate = endDate;
	}
}
